package com.sgj.prototype.deepclone;

/**
 * 原型模式
 * @Author: Guoji Shen
 * @Date: 2021/11/15 8:48
 */
public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        DeepProtoType p = new DeepProtoType();
        p.name = "宋江";
        p.deepCloneableTarget = new DeepCloneableTarget("大牛", "小牛");

        // 方式一完成深拷贝
        // DeepProtoType p2 = (DeepProtoType) p.clone();
        // System.out.println("p.name = " + p.getName() + " p.deepCloneableTarget = " + p.getDeepCloneableTarget().hashCode());
        // System.out.println("p2.name = " + p2.getName() + " p2.deepCloneableTarget = " + p2.getDeepCloneableTarget().hashCode());

        // 方式二完成深拷贝
        DeepProtoType p2 = (DeepProtoType) p.deepClone();
        System.out.println("p.name = " + p.getName() + " p.deepCloneableTarget = " + p.getDeepCloneableTarget().hashCode());
        System.out.println("p2.name = " + p2.getName() + " p2.deepCloneableTarget = " + p2.getDeepCloneableTarget().hashCode());
    }
}